-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix race condition in test #337
Conversation
@@ -31,29 +50,31 @@ func TestDeviceTickerBasic(t *testing.T) { | |||
DeviceID: "b", | |||
}) | |||
time.Sleep(duration * 2) | |||
if len(payloads) != 1 { | |||
t.Fatalf("expected 1 callback, got %d", len(payloads)) | |||
result := payloads.clone() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to clone here, sorry?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd need to lock every time we access the underlying slice, which could then lead to inconsistent results (e.g len=1 when len() is called, but then increases to len=2 later on. It's easier to snapshot the slice.
func setTimeSinceValue(val time.Duration) { | ||
timeSinceMu.Lock() | ||
timeSinceValue = time.Minute * 2 | ||
timeSinceMu.Unlock() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val seems unused here?
Implements half of #243 in a different way which involves less error prone locking.